package com.xyy.saas.payment.merchant.core.dto;

import com.xyy.saas.payment.util.AmountCastUtil;
import lombok.Builder;
import lombok.Data;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Data
@Builder
public class WithdrawRefundVo {
    /**
     * 本次返回的记录数
     */
    private String resultNum;
    /**
     * 退汇明细
     */
    private List<WithdrawRefundItem> withdrawRefundItems;

    /**
     * 解析明细
     */
    public static List<WithdrawRefundItem> parseItems(List<Map<String, String>> param) {
        if(CollectionUtils.isEmpty(param)) {
            return null;
        }

        List<WithdrawRefundItem> items = new ArrayList<>();

        for(Map<String, String> item : param) {
            items.add(WithdrawRefundItem.builder().
                    bankTradeNo(item.get("OldFrontSeqNo")).
                    withdrawNo(item.get("OldMarketSeqNo")).
                    remark(item.get("OldAddMsg")).
                    amount(AmountCastUtil.castYuan2Fen(item.get("RejectInAcctTranAmt"))).
                    refundReason(item.get("RejectBillReason")).
                    refundDate(item.get("RejectBillDate")).
                    payeeAccountNo(item.get("RejectInPayerAcctNo")).
                    payerAccountName(item.get("RejectInPayerAcctName")).
                    payerBranchCode(item.get("RejectInPayerBranchId")).
                    payerBranchName(item.get("RejectInPayerBranchName")).
                    payeeAccountNo(item.get("PayeeWitnessSubAcctNo")).
                    payeeBankTradeNo(item.get("PayeeFrontSeqNo")).
                    build());
        }

        return items;
    }
}
